import http from '@/utils/http'

// 查询角色列表
export function listRole (params) {
  return http({
    url: '/system/role/list',
    method: 'post',
    data: http.adornData(params)
  })
}

// 查询角色详细
export function getRole (roleId) {
  return http({
    url: '/system/role/info/' + roleId,
    method: 'get'
  })
}

// 角色数据权限
export function authDataScope (data) {
  return http({
    url: '/system/role/authDataScope',
    method: 'post',
    data: http.adornData(data)
  })
}

// 角色状态修改
export function changeRoleStatus (id, status) {
  const data = {
    id,
    status
  }
  return http({
    url: '/system/role/changeStatus',
    method: 'put',
    data: data
  })
}

// 删除角色
export function delRole (roleId) {
  return http({
    url: '/system/role/' + roleId,
    method: 'delete'
  })
}

// 导出角色
export function exportRole(query, filename) {
  return http.download('system/role/export', { ...query }, filename)
}

// 校验角色名称唯一性
export function checkRoleNameUnique (data) {
  return http({
    url: '/system/role/checkRoleNameUnique',
    method: 'get',
    params: http.adornParams(data)
  })
}

// 校验角色名称唯一性
export function checkRoleKeyUnique (data) {
  return http({
    url: '/system/role/checkRoleKeyUnique',
    method: 'get',
    params: http.adornParams(data)
  })
}

// 查询最大排序
export function findMaxSort () {
  return http({
    url: '/system/role/findMaxSort',
    method: 'get'
  })
}
// 批量新增更新角色
export function batchSaveRole (data) {
  return http({
    url: '/system/role/batchSaveRole',
    method: 'post',
    data: data
  })
}
// 批量删除角色
export function batchDeleteRole(data) {
  return http({
    url: '/system/role/batchDeleteRole',
    method: 'post',
    data: data
  })
}

// 删除角色
export function delRoleUser (roleId, userIds) {
  return http({
    url: '/system/role/deleteRoleUser/' + roleId + '/' + userIds,
    method: 'post'
  })
}

// 插入角色用户
export function addRoleUser(roleId, userIds) {
  return http({
    url: `/system/role/addRoleUser/${roleId}/${userIds}`,
    method: 'post'
  })
}

// 修改角色
export function addRoleMenu(roleId, menuIds) {
  return http({
    url: `/system/role/addRoleMenu`,
    method: 'post',
    data: http.adornData({
      roleId: roleId,
      menuIds: menuIds
    })
  })
}
